def proverka(z):
    d=0
    for i in range(2, int(z**0.5)+1):
        if z%i==0:
            d+=1
    if d==0:
        return 1
    else:
        return 0
b=input()
z=0
for  l in range(0,4):
    for i in range(4,0,-1):
        if i>l:
            if proverka(int(b[l:i]))==1:
                if int(b[l:i])>z:
                    z=int(b[l:i])
print(z)
